import { defineStore } from 'pinia'

export const useMain = defineStore('main', {
    state: () => {
        return {
            online: 0,
            email: '',
            token: localStorage.getItem('t') || null,
            systemUserMessage: {} as any,
            isShwoMenu: true
        }
    },
    getters: {
        obtainIsShwoMenu: (state) => {
            return state.isShwoMenu;
        },
        obtainOnline: (state) => {
            return state.online;
        },
        obtainToken: (state) => {
            return state.token
        },
        obtainEmail: (state) => {
            return state.email
        },
        obtainUserSystemMessage: (state) => {
            return state.systemUserMessage;
        },
    },
    actions: {
        setIsShwoMenu(value: boolean) {
            this.isShwoMenu = value;
        },
        insterToken(value: string) {
            this.token = value
        },
        insertOnlinerCount(value: number) {
            this.online = value;
        },
        deleteToken() {
            localStorage.removeItem('t');
            this.token = null;
        },
        setSystemMessage(data: any) {
            this.systemUserMessage = (data as never);
        },
        setCurrentEmail(value: string) {
            this.email = value;
        }
    },
})